<?php

namespace App\Http\Requests\Api;

class PartTimeJobRequest extends ApiRequest
{
    public function rules()
    {
        $time_start_check = '';
        $time_end_check = '';
        if ($this->input('long_term', 0) == 0) {
            $time_start_check = 'required';
            $time_end_check = 'bail|required';
        }

        return [
            'id' => $this->is('*/update') ? 'bail|required|integer' : '',
            'com_id' => $this->is('*/create') ? 'bail|required|integer' : '',
            'title' => 'bail|required|min:3',
            'type_id' => 'bail|required|integer',
            'long_term' => 'bail|required|integer|between:0,1',
            'time_start' => $time_start_check,
            'time_end' => $time_end_check . ($this->time_start != $this->time_end ? '|after:time_start' : ''),
            'free_time' => 'required',
            'need_num' => 'bail|required|integer|min:0',
            'sex' => 'bail|required|integer|between:0,2',
            'education' => 'bail|required|integer',
            'salary_price' => 'bail|required|integer',
            'salary_unit' => 'bail|required|integer',
            'salary_method' => 'bail|required|integer',
            'city_id' => 'bail|required|integer',
            'address' => 'bail|required|min:3',
            'longitude' => 'numeric',
            'latitude' => 'numeric',
            'content' => 'required|min:3',
            'contacts' => 'required|min:2',
            'mobile' => 'bail|required_without:phone|mobile_verification',
            'phone' => 'bail|required_without:mobile|check_company_phone',
        ];
    }

    public function attributes()
    {
        return [
            'com_id' => '公司id',
            'title' => '兼职名称',
            'type_id' => '兼职类型',
            'long_term' => '是否长期',
            'time_start' => '开始日期',
            'time_end' => '结束日期',
            'free_time' => '时间表',
            'need_num' => '招聘人数',
            'sex' => '性别要求',
            'education' => '学历要求',
            'salary_price' => '工资待遇金额',
            'salary_unit' => '金额单位',
            'salary_method' => '结算方式',
            'city_id' => '工作城市',
            'address' => '详细地址',
            'longitude' => '经度',
            'latitude' => '纬度',
            'coordinate_address' => '坐标地址',
            'content' => '兼职详情',
            'contacts' => '联系人',
            'mobile' => '手机号',
            'phone' => '电话',
        ];
    }

    public function messages()
    {
        return array_merge(parent::messages(), [
            'time_end.after' => '结束日期需要大于开始日期',
            'mobile.required_without' => '固定电话与手机号码必须填写一项',
            'mobile.mobile_verification'=>'请输入正确的手机号码',
            'phone.required_without' => '固定电话与手机号码必须填写一项',
            'phone.check_company_phone'=>'请输入正确的区号和电话号码',
        ]);
    }
}
